<template>
    <div>
        <!-- 头部区域 -->
         <div class="header">
            <!-- 标题 -->
             <div class="title">
                <img class="logo" src="../assets/logo.svg">
                药物管理后台管理系统
            </div>
            
             <!-- 中间区域 -->
              <div class="center">
              </div>
             <!-- 名字头像 -->
             <div class="img">
                <img class="avatar" v-if="data.user?.avatar" :src="data.user?.avatar+'?t='+Date.now()">
                <img class="avatar" v-else src="../assets/logo.svg">
                <el-dropdown>
                    <span class="el-dropdown-link">
                    {{ data.user?.name}}
                    <el-icon class="el-icon--right">
                        <arrow-down />
                    </el-icon>
                    </span>
                    <template #dropdown>
                    <el-dropdown-menu>
                        <el-dropdown-item @click="router.push('/person')">个人信息</el-dropdown-item>
                        <el-dropdown-item @click="router.push('/password')">修改密码</el-dropdown-item>
                        <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                    </el-dropdown-menu>
                    </template>
                </el-dropdown>
                
                <!-- <span class="username">张三</span>  -->
            </div>

         </div>
        
         <!-- 下部 -->
          <div class="button">
            <!-- 侧边栏 -->
            <div class="sidebar">
                <el-menu router  default-active="/"  style="min-height: calc(100vh - 60px);">   
                    <el-menu-item index="/">
                        <el-icon><House /></el-icon>
                        <span>首页</span>
                    </el-menu-item>
                    <el-sub-menu index="1" v-if="data.user.role==='ADMIN'">
                        <template #title>
                            <el-icon><User /></el-icon>
                            <span>用户管理</span>
                        </template>
                        <el-menu-item index="/admin">管理员信息</el-menu-item>
                        <el-menu-item index="/user">用户信息</el-menu-item>
                    </el-sub-menu>
                    <el-sub-menu index="2">
                        <template #title>
                            <el-icon><Monitor /></el-icon>
                            <span>信息管理</span>
                        </template>
                        <el-menu-item index="/notice">系统公告</el-menu-item>
                        <el-menu-item index="/introduction">旅游攻略</el-menu-item>
                        <el-menu-item index="/category">攻略分类</el-menu-item>
                    </el-sub-menu>
                </el-menu>
            </div>
            <!-- 内容区域 -->
             <div class="content">
                
                <el-card class="card">
                    <!-- <div style="display: flex;">
                        <div style="flex: 1; display: flex; align-items: center; padding-left: 20px; border-bottom: 1px solid #ddd">
                            首页 / 数据分析
                        </div>
                    </div> -->
                    <RouterView @updateUser="updateUser"/>
                </el-card>

                <!-- <RouterView/> -->
             </div>
          </div>
          
       
    </div>
</template>
<script setup>
import router from '@/router'
import { reactive } from 'vue'

const data=reactive({
    user:JSON.parse(localStorage.getItem('code_user')||{})
})
const logout=()=>{
    localStorage.removeItem('code_user')
    router.push('/login')
}

const userStr=localStorage.getItem('code_user')
if(userStr){
    const user=JSON.parse(userStr)
    if(!user.id){
        router.push('/login')
    }
}else{
    router.push('/login')
}
const updateUser = () => {
  data.user = JSON.parse(localStorage.getItem("code_user") || '{}')
}
</script>
<style lang="scss" scoped >
.header{
    height: 80px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #ccc;
    // background: #EBF1F6;

    .title{
        font-size: 20px;
        font-weight: 600;
        color: rgb(89, 143, 143);
        display: flex;
        align-items: center;
        margin-left: 30px;

        .logo{
            width: 40px;
            height: 40px;
            border-radius: 50%;
            margin-right: 10px;
        }
    }
    
    .center{
        flex: 1;
    }

    .img {
        display: flex;
        align-items: center;
        gap: 6px; 
        padding-right: 20px;

        .avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
        }
    }
}
.button{
    display: flex;
    background: #F0F2F5;
    .sidebar{
        width: 220px;
        background: #EBF1F6;
        font-weight: 550;
    }
    .content{
        flex:1;
        display: flex;
        align-items: center;
        justify-content: center;    
        .card{
            width: 97%;
            height: 97%;
        }
    }
}
.el-menu .is-active{
    background-color: #c5daf4

}
.el-sub-menu.is-active {
    background-color: transparent !important;
}
.el-tooltip__trigger{
    outline: none;
}
.el-dropdown{
    cursor: pointer;
}

.el-menu--inline .el-menu-item{
    margin-left: 15px;
}

</style>